<?php
class Default_Form_ValidateLogin{
	
	//CHUA NHUNG THONG BAO LOI CUA FORM
	protected $_messagesError = null;
	
	//MANG CHUA DU LIEU SAU KHI KIEM TRA
	protected  $_arrData;
	
	public function __construct($arrParam = array(), $options = null){
		
		//=========================================
		//KIEM TRA USER NAME
		//==========================================
		
		$validator = new Zend_Validate();
		$validator->addValidator(new Zendvn_Validate_NotEmpty(),true)
				  ->addValidator(new Zendvn_Validate_StringLength(4,32))
				  ->addValidator(new Zendvn_Validate_Regex('#^[a-zA-Z0-9\-_\s\.]+$#'),true);				  
		if(!$validator->isValid($arrParam['user_name'])){
			$message = $validator->getMessages();
			$this->_messagesError['user_name'] = 'Tài khoản sai quy định';
			$arrParam['user_name']='';
		}
		//=========================================
		//KIEM TRA PASSWORD
		$validator = new Zend_Validate();
		$validator->addValidator(new Zendvn_Validate_NotEmpty(),true)
				  ->addValidator(new Zendvn_Validate_StringLength(4,32))
				  ->addValidator(new Zendvn_Validate_Regex('#^[a-zA-Z0-9\-_\s\.]+$#'),true);
			if(!$validator->isValid($arrParam['password'])){
				$message = $validator->getMessages();
				$this->_messagesError['password'] = 'Mật khẩu sai quy định';
				$arrParam['password']='';
			}
		//=========================================
		//TRUYEN CAC GIA TRI DUNG VAO $_arrData
		//==========================================
		$this->_arrData = $arrParam;
	}
	
	//KIEM TRA LOI
	//return true neu co loi xay ra
	public function isError(){
		if(count($this->_messagesError)>0){
			return true;
		}else{
			return false;
		}
		
	}
	
	//TRA VE MOT MANG CAC LOI
	public function getMessageError(){
		return $this->_messagesError;
	}
	
	//TRA VE MOT MANG DU LIEU SAU KHI KIEM TRA
	public function getData($options = null){
		return $this->_arrData;
	}
}	
	